<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div style="width:100%">
              <div style="width:100%">
                  <table>
                      <tr>
                          <td>快速查询</td>
                          <td>
                              <el-input v-model="txtsearch" placeholder="供应商代码|名称|助记符" @keyup.enter.native="filterQuery" style="width:160px" :disabled="bChangeFlag"></el-input>
                          </td>
                          <td>类别</td>
                          <td>
                              <el-select v-model="selVendorclass" style="width:120px" placeholder="请选择" @dblclick.native="getRow(row)" clearable @change="BtnQuery" :disabled="bChangeFlag">
                                  <el-option v-for="item in selVendorclassOptions" :key="item.key" :label="item.label+'['+item.value+']'" :value="item.value">
                                  </el-option>
                              </el-select>
                          </td>
                          <td align="right">状态</td>
                          <td align="left">
                              <el-radio-group v-model="status" style="width:100%" @change="BtnQuery">
                                  <el-radio :label="'0'">在用&nbsp; &nbsp;&nbsp;</el-radio>
                                  <el-radio :label="'1'">停用</el-radio>
                                  <el-radio :label="'A'">全部</el-radio>
                              </el-radio-group>
                          </td>
                          <td>
                              <div width="160px" style="text-align:center"><span style="color:RoyalBlue;font-size:16px;font-weight:bold;padding: 0 0 0 15px">当前采购中心:{{logininvorgna}}</span></div>
                          </td>
                      </tr>
                  </table>
              </div>

              <div style="width:100%;">
                  <div style="float:right;padding-right:5px">
                      <el-button @click="BtnQuery" icon="el-icon-search" type="primary" v-if="bPINQUERY" :disabled="bChangeFlag">查询</el-button>
                      <el-button @click="BtnAdd" icon="el-icon-plus" v-if="bPADD" :disabled="bChangeFlag">新增</el-button>
                      <el-button @click="BtnDel" icon="el-icon-delete" v-if="bPDELETE" :disabled="bChangeFlag">删除</el-button>
                      <el-button @click="BtnSave" icon="el-icon-document" v-if="bPMODIFY" :disabled="!bChangeFlag">保存</el-button>
                      <el-button @click="BtnClear" icon="el-icon-close" :disabled="!bChangeFlag">取消</el-button>
                      <el-button @click="BtnSync" icon="el-icon-position" :disabled="bChangeFlag">同步</el-button>
                      <el-button @click="BtnExport" icon="el-icon-download" :disabled="bChangeFlag">导出</el-button>
                      <el-button @click="BtnClose" icon="el-icon-close">退出</el-button>
                  </div>
              </div>
          </div>

      </div>
      <div class="pagecenter">
          <rm-layout-right splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="540">
              <div style="height:100%">
                  <vxe-table :data.sync="showLXTableData" :loading="bLoading" :keyboard-local-config="keyLocalConfig" :row-class-name="lRowClassName" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{
          trigger: 'click',
          mode: 'cell',
          showStatus: true,
          showIcon: false,
        }" @current-change="CurrentChangeEvent" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="lXTable" resizable size="mini" stripe show-header-overflow="tooltip" show-overflow="tooltip">
                      <vxe-table-column type="index" title="NO." width="45" sortable></vxe-table-column>
                      <vxe-table-column field="vendorclass" title="类别" width="60" :formatter="formatFun" sortable></vxe-table-column>
                      <vxe-table-column field="invorgid" title="采购中心" width="120" :formatter="formatFun"></vxe-table-column>
                      <vxe-table-column field="vendorcode" title="代码" width="60" sortable></vxe-table-column>
                      <vxe-table-column field="vendorname" title="名称" width="180" header-align="center" align="left" sortable></vxe-table-column>
                      <vxe-table-column field="vendorid" title="ID" width="40" align="center" sortable></vxe-table-column>
                      <vxe-table-column field="vendorna" title="简称" width="120" header-align="center" align="left" sortable></vxe-table-column>
                      <vxe-table-column field="inputcode" title="助记符" width="70"></vxe-table-column>
                      <vxe-table-column field="stopflag" title="状态" width="40" align="center" :formatter="formatFun" sortable></vxe-table-column>
                      <vxe-table-column field="contactman" title="联系人" width="60" align="center" sortable></vxe-table-column>
                      <vxe-table-column field="phonecode" title="电话" width="100" sortable></vxe-table-column>
                      <vxe-table-column field="address" title="地址" width="200" header-align="center" align="left" sortable></vxe-table-column>
                      <vxe-table-column field="homepage" title="主页" width="120" sortable></vxe-table-column>
                      <vxe-table-column field="email" title="电子邮箱" width="120" sortable></vxe-table-column>
                      <vxe-table-column field="description" title="备注" width="200" header-align="center" align="left" sortable></vxe-table-column>
                      <!-- <vxe-table-column field="labdeptid" title="检验科室" width="100" align="center" sortable></vxe-table-column> -->
                  </vxe-table>
              </div>
              <template v-slot:fix>
                  <div v-loading="bPageInitLoading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" style="height:100%">
                      <el-tabs style="height:100%;" type="border-card" @tab-click="HandleClick" v-model="activeTabName">
                          <el-tab-pane label="基础信息" name="tabname_jcxx">
                              <div style="height:100%;border:1px solid #CCC">
                                  <el-form :label-position="labelPosition" label-width="80px" :model="detailData" :disabled="bNullFlag">
                                      <table class="table1style" style="width:100%;font-size:12px">
                                          <tr>
                                              <td align="right">供应商ID</td>
                                              <td>
                                                  <el-input v-model="detailData.vendorid" @input="HasChange" :disabled="true" witdh="100%"></el-input>
                                              </td>
                                              <td align="right" style="color:#F56C6C">采购中心</td>
                                              <td>
                                                  <el-select v-model="detailData.invorgid" style="width:100%" :disabled="true">
                                                      <el-option v-for="item in invorgOptions" :key="item.key" :label="item.label+'['+item.value+']'" :value="item.value">
                                                      </el-option>
                                                  </el-select>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right" style="color:#F56C6C">供应商代码</td>
                                              <td>
                                                  <el-input v-model="detailData.vendorcode" @input="HasChange" @change="ChkKeyId" witdh="100%" ref="input1" @keyup.enter.native="NextFocus(1)" @focus="Focus($event)"></el-input>
                                              </td>
                                              <td colspan="2" align="left">
                                                  <!-- 查看证书功能待添加。 -->
                                                  <el-button @click="BtnAdd" icon="el-icon-postcard" :disabled="true">查看证书</el-button>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right" style="color:#F56C6C">供应商名称</td>
                                              <td>
                                                  <el-input v-model="detailData.vendorname" @input="HasChange" witdh="100%" ref="input2" @keyup.enter.native="NextFocus(2)" @blur="getInputCode()" @focus="Focus($event)"></el-input>
                                              </td>
                                              <td align="right">助记符</td>
                                              <td>
                                                  <el-input v-model="detailData.inputcode" @change="HasChange" witdh="100%" ref="input3" @keyup.enter.native="NextFocus(3)" @focus="Focus($event)"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">供应商简称</td>
                                              <td>
                                                  <el-input v-model="detailData.vendorna" @input="HasChange" witdh="100%" ref="input4" @keyup.enter.native="NextFocus(4)" @focus="Focus($event)"></el-input>
                                              </td>
                                              <td align="right">停用</td>
                                              <td>
                                                  <el-checkbox style="width:100%;" v-model="detailData.stopflag" true-label="1" false-label="0" @input="HasChange" witdh="100%" ref="input5" @keyup.enter.native="NextFocus(5)"></el-checkbox>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right" style="color:#F56C6C">供应商类别</td>
                                              <td>
                                                  <el-select v-model="detailData.vendorclass" style="width:100%" ref="input6" @keyup.enter.native="NextFocus(6)" placeholder="请选择" clearable @change="HasChange">
                                                      <el-option v-for="item in selVendorclassOptions" :key="item.key" :label="item.label+'['+item.value+']'" :value="item.value" @focus="Focus($event)">
                                                      </el-option>
                                                  </el-select>
                                              </td>
                                              <!-- <td align="right">检验科室</td>
                                              <td>
                                                  <el-select v-model="detailData.labdeptid" style="width:100%" placeholder="请选择" clearable @change="HasChange" ref="input7" @keyup.enter.native="NextFocus(7)">
                                                      <el-option v-for="item in labgroupOptions" :key="item.key" :label="item.hidname+'['+item.hidkey+']'" :value="item.hidkey">
                                                      </el-option>
                                                  </el-select>
                                              </td> -->
                                          </tr>
                                          <tr>
                                              <td align="right">联系人</td>
                                              <td>
                                                  <el-input v-model="detailData.contactman" @input="HasChange" witdh="100%" ref="input8" @keyup.enter.native="NextFocus(8)" @focus="Focus($event)"></el-input>
                                              </td>
                                              <td align="right">电话</td>
                                              <td>
                                                  <el-input v-model="detailData.phonecode" @input="HasChange" witdh="100%" ref="input9" @keyup.enter.native="NextFocus(9)" @focus="Focus($event)"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">地址</td>
                                              <td colspan="3">
                                                  <el-input v-model="detailData.address" @input="HasChange" witdh="100%" ref="input10" @keyup.enter.native="NextFocus(10)" @focus="Focus($event)"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">主页</td>
                                              <td colspan="3">
                                                  <el-input v-model="detailData.homepage" @input="HasChange" witdh="100%" ref="input11" @keyup.enter.native="NextFocus(11)" @focus="Focus($event)"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">电子邮件</td>
                                              <td colspan="3">
                                                  <el-input v-model="detailData.email" @input="HasChange" witdh="100%" ref="input12" @keyup.enter.native="NextFocus(12)" @focus="Focus($event)"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right" style="vertical-align:top">备注</td>
                                              <td colspan="4">
                                                  <el-input type="textarea" :rows="4" v-model="detailData.description" @input="HasChange" witdh="100%" ref="input13" @keyup.enter.native="NextFocus(13)" @focus="Focus($event)"></el-input>
                                              </td>
                                          </tr>
                                      </table>
                                  </el-form>
                              </div>
                          </el-tab-pane>
                          <el-tab-pane label="评价登记" name="tabname_pjdj">
                              <div style="height: 100%;">
                                  <div style="height:100%;width:100%;background-color:#ddccbb;">
                                      <vxe-table :data="rXTableData" :key="pjdjkey" :keyboard-config="selKeyConfig" :keyboard-local-config="selKeyLocalConfig" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{
                                                  trigger: 'click',
                                                  mode: 'row', 
                                                  showStatus: true,
                                                  activeMethod: ActiveMethod,
                                                  showIcon: false,
                                              }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="rXTable" resizable size="mini" stripe :row-class-name="rRowClassName" :cell-class-name="rCellClassName" :mouse-config="{selected: true}" show-header-overflow="tooltip" show-overflow="tooltip">
                                          <vxe-table-column field="vendevkind" title="评价项目" width="120" :edit-render="{
                                                          name: 'select',
                                                          options:vendevkindOptions,
                                                           events:{change:(row,val) => {row.row.vendevkind = val.target.value;HasChange()}}
                                                          }"> </vxe-table-column>
                                          <vxe-table-column field="evaltext" title="评价内容" width="220" align="center">
                                              <template v-slot="{ row }">
                                                  <el-input v-model="row.evaltext" type="textarea" autosize @focus="Focus($event)" @input="HasChange"></el-input>
                                              </template>
                                          </vxe-table-column>
                                          <vxe-table-column field="createdate" title="创建日期" width="80" :formatter="['toDateString', 'yyyy-MM-dd']" align="center"></vxe-table-column>
                                          <vxe-table-column field="createuserna" title="创建人" width="60" align="center"></vxe-table-column>
                                          <vxe-table-column field="vendevid" title="ID" width="40" align="center"></vxe-table-column>
                                          <template v-slot:fix>
                                              <div style="font-size:17px;padding:3px;background-color:#fff;font-weight:bold">
                                                  <el-button class="el-button--310" @click.native="BtnDetailAdd" :disabled="bNullFlag">新增评价</el-button>
                                                  <el-button class="el-button--310" @click.native="BtnDetailDel" :disabled="bNullFlag">删除评价</el-button>
                                              </div>
                                          </template>
                                      </vxe-table>
                                  </div>
                              </div>
                          </el-tab-pane>
                      </el-tabs>
                  </div>
              </template>
          </rm-layout-right>
      </div>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "INV123",
  data() {
      return {
          txtsearch: "",
          selVendorclass: "", //供应商类别
          status: "A", //状态
          logininvorgid: "",
          logininvorgna: "",
          actionindex: "M",
          labelPosition: "right",
          activeTabName: "tabname_jcxx", //默认Tab页
          pjdjkey: 0, //初始化空数据表格的高度
          bLoading: false,
          bNullFlag: false,
          bChangeFlag: false,
          bPageInitLoading: false,
          selKeyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          selKeyLocalConfig: {
              isArrow: true,
          },
          keyLocalConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
              isArrow: true,
          },
          detailData: {
              vendorid: 0, //int   not null, 	--供应商ID
              invorgid: -1, //int   not null, 	--采购中心ID  -1=全局，分两个菜单维护
              invorgna: "全局",
              vendorcode: "", //varchar(20)    not null, 	--供应商代码
              vendorname: "", //varchar(64)    not null, 	--供应商名称
              vendorclass: "", //varchar(20)    null, 	--供应商类别  01=厂商，02=经销商，03=代理商
              address: "", //varchar(128)   null, 	--地址
              contactman: "", //varchar(64)    null, 	--联系人
              phonecode: "", //varchar(64)    null, 	--电话
              homepage: "", //varchar(128)   null, 	--主页
              email: "", //varchar(64)    null, 	--电子邮件
              description: "", //varchar(1024)  null, 	--备注信息
              inputcode: "", //varchar(20)    null, 	--助记符
              vendorna: "", //varchar(32)    null, 	--供应商简称
              labdeptid: "0", //int            null, 	--所属检验科室  该字段为空 或 =0 代表所有科室都能使用
              stopflag: "0", //char(1) default ('0') not null, 	--停用标志  0=在用  1=停用
          },
          selectConfig: { tigger: "row" },
          tmpdetailData: {},
          selrow: [],
          AddData: [], //新增数据 用于变色
          ModData: [], //修改数据 用于变色
          lXTableData: [],
          rXTableData: [],
          showLXTableData: [],
          invorgOptions: [], //采购中心Option
          labgroupOptions: [], //所属检验科室Option
          vendevkindOptions: [], //评价项目名
          selVendorclassOptions: [
              //供应商类别Option
              { value: "01", label: "厂商" },
              { value: "02", label: "经销商" },
              { value: "03", label: "代理商" },
          ],
          bPINQUERY: false,
          bPADD: false,
          bPDELETE: false,
          bPMODIFY: false,
      };
  },
  created() {
      this.logininvorgid = this.$tool.getSession(this.$tool.selinvorg);
      this.getbuttonpower();
      this.ddlQuery_invorgid();
      this.ddlQuery_VendevKind();
      this.ddlQuery_Labgroup();
  },
  computed: {},
  methods: {
      //格式化表格数据
      formatFun({ cellValue, column, row }) {
          if (column.property == "vendorclass") {
              try {
                  let vendorclassna = this.selVendorclassOptions.find((m) => m.value == cellValue);
                  if (vendorclassna != undefined && vendorclassna != null) {
                      return vendorclassna.label;
                  } else {
                      return cellValue;
                  }
              } catch {}
          } else if (column.property == "invorgid") {
              try {
                  let invorgna = this.invorgOptions.find((m) => m.value == cellValue);
                  if (invorgna != undefined && invorgna != null) {
                      return invorgna.label;
                  } else {
                      return cellValue;
                  }
              } catch {}
          } else if (column.property == "stopflag") {
              try {
                  let stopflagna = this.$opt.stopFlagOption.find((m) => m.value == cellValue);
                  if (stopflagna != undefined && stopflagna != null) {
                      return stopflagna.label;
                  } else {
                      return cellValue;
                  }
              } catch {}
          } else if (column.property == "labdeptid") {
              try {
                  if (cellValue == "" || cellValue == undefined || cellValue == null) {
                      return "全部";
                  } else {
                      let labgroupna = this.labgroupOptions.find((m) => m.hidkey == cellValue);
                      if (labgroupna != undefined && labgroupna != null) {
                          return labgroupna.hidname;
                      } else {
                          return cellValue;
                      }
                  }
              } catch {}
          }
      },
      //刷新无数据表格高度
      HandleClick(tab, evt) {
          this.pjdjkey++;
      },
      //----------------- 查询类 ----------------- //
      //查询--按钮权限
      //*用于质控，在无耗材模块下维护试剂供应商，厂商。
      async getbuttonpower() {
          try {
              const res = await this.$tool.request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  data: {
                      action: "getbuttonpower",
                  },
              });
              if (res) {
                  this.bPINQUERY = res.bPINQUERY;
                  this.bPADD = res.bPADD;
                  this.bPDELETE = res.bPDELETE;
                  this.bPMODIFY = res.bPMODIFY;
              }
          } catch (e) {
              this.$alert(e);
          }
      },
      //查询--采购中心
      ddlQuery_invorgid() {
          this.$tool
              .request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  data: {
                      action: "ddl_invorgid",
                  },
              })
              .then((res) => {
                  this.invorgOptions = res.dt;
                  this.logininvorgna = res.logininvorgna;
              })
              .catch((e) => {
                  this.$alert(e, "出错");
              });
      },
      async ddlQuery_Labgroup() {
          try {
              const res = await this.$tool.request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  data: {
                      action: "ddl_labdept",
                  },
              });
              if (res.rc.length > 0) {
                  this.labgroupOptions = res.rc;
                  this.BtnQuery();
              } else {
                  this.labgroupOptions = [];
              }
          } catch (e) {
              this.$alert(e);
          }
      },
      //查询--评价项目
      async ddlQuery_VendevKind() {
          try {
              const res = await this.$tool.request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  data: {
                      action: "ddl_vendevkind",
                  },
              });
              if (res.dt.length > 0) {
                  this.vendevkindOptions = res.dt;
                  this.BtnQuery();
              } else {
                  this.vendevkindOptions = [];
              }
          } catch (e) {
              this.$alert(e);
          }
      },
      //快速查找
      filterQuery() {
          let filterName = this.txtsearch.trim();
          if (filterName) {
              let rest = this.lXTableData.filter((item) => {
                  return item.vendorcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || (item.inputcode ? item.inputcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.vendorname ? item.vendorname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false);
              });
              this.showLXTableData = rest;
          } else {
              this.showLXTableData = this.lXTableData;
          }
          let row = this.showLXTableData[0];
          if (row) {
              this.HightLightRow(row);
          } else {
              this.HightLightRow(false);
          }
      },
      //主表查询
      BtnQuery() {
          this.AddData = [];
          this.ModData = [];
          this.bLoading = true;
          this.$tool
              .request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  data: {
                      action: "inv_vendor_query",
                      vendorclass: this.selVendorclass,
                      status: this.status,
                  },
              })
              .then((res) => {
                  this.lXTableData = res.data;
                  this.filterQuery();
                  if (this.lXTableData.length == 0) this.actionindex = "A";
                  this.bLoading = false;
              })
              .catch((e) => {
                  this.ErrorCatch(e, "", "error");
                  this.bLoading = false;
              });
      },
      //明细查询 -- 主表，子表
      async detailQuery(row) {
          try {
              this.selrow = row;
              this.actionindex = "M";
              this.bPageInitLoading = true;
              const res = await this.$tool.request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  data: {
                      action: "inv_vendor_query_detail",
                      vendorid: row.vendorid,
                  },
              });
              if (res.invvendor.length > 0) {
                  this.detailData = res.invvendor[0];
                  this.rXTableData = res.invvendoreval;
              } else {
                  this.detailData = {};
                  this.rXTableData = [];
              }
              this.tmpdetailData = XEUtils.clone(this.detailData, true);
              this.bPageInitLoading = false;
          } catch (e) {
              this.ErrorCatch(e, "", "error");
              this.bPageInitLoading = false;
          }
      },
      //主键查询  是否重复
      ChkKeyId() {
          this.$tool
              .request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  data: {
                      action: "inv_vendor_chkkeyid",
                      vendorcode: this.detailData.vendorcode,
                  },
              })
              .then((res) => {
                  if (res == "1") {
                      this.$alert("供应商代码重复，请重新填写！");
                      this.$refs.input1.focus();
                  }
              })
              .catch((e) => {
                  this.ErrorCatch(e, "", "error");
              });
      },
      //----------------- 按钮类 -----------------//
      //新增
      BtnAdd() {
          this.bChangeFlag = true;
          this.bNullFlag = false;
          this.activeTabName = "tabname_jcxx";
          this.actionindex = "A";
          this.detailData = {
              vendorid: "", //int   not null, 	--供应商ID
              invorgid: this.$tool.getSession(this.$tool.selinvorg), //int   not null, 	--采购中心ID  -1=全局，分两个菜单维护
              invorgna: this.logininvorgna,
              vendorcode: "", //varchar(20)    not null, 	--供应商代码
              vendorname: "", //varchar(64)    not null, 	--供应商名称
              vendorclass: "", //varchar(20)    null, 	--供应商类别  01=厂商，02=经销商，03=代理商
              address: "", //varchar(128)   null, 	--地址
              contactman: "", //varchar(64)    null, 	--联系人
              phonecode: "", //varchar(64)    null, 	--电话
              homepage: "", //varchar(128)   null, 	--主页
              email: "", //varchar(64)    null, 	--电子邮件
              description: "", //varchar(1024)  null, 	--备注信息
              inputcode: "", //varchar(20)    null, 	--助记符
              vendorna: "", //varchar(32)    null, 	--供应商简称
              labdeptid: 0, //int            null, 	--所属检验科室  该字段为空 或 =0 代表所有科室都能使用
              stopflag: "0", //char(1) default ('0') not null, 	--停用标志  0=在用  1=停用
          };
          this.rXTableData = [];
          setTimeout(() => {
              this.$refs.input1.focus();
          }, 30);
      },
      //新增明细
      BtnDetailAdd() {
          this.$refs.rXTable.insertAt(
              {
                  vendorid: this.detailData.vendorid,
                  vendevkind: "",
                  evaltext: "",
                  createdate: "",
                  createuser: "",
                  vendevId: "",
              },
              -1
          ),
              this.$refs.rXTable.setActiveRow(this.$refs.rXTable.tableData[this.$refs.rXTable.tableData.length - 1], "vendevkind"),
              this.$refs.rXTable.scrollToRow(this.$refs.rXTable.tableData[this.$refs.rXTable.tableData.length - 1]),
              (this.bChangeFlag = true);
      },
      //删除明细
      BtnDetailDel() {
          try {
              var delrow = this.$refs.rXTable.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.rXTable.tableData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.rXTable.remove(delrow);
                  let havedata = this.$refs.rXTable.tableData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.rXTable.setCurrentRow(selectrow);
                  } else {
                      this.$refs.rXTable.setCurrentRow(null);
                  }
                  this.bChangeFlag = true;
              }
          } catch (e) {
              console.log("error", e);
          }
      },
      //删除 -- 弹窗提示
      BtnDel() {
          var delrow = this.$refs.lXTable.getCurrentRow();
          this.$confirm('确定删除供应商名称为<b style="color:red">' + delrow.vendorname + "</b>的记录吗？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              dangerouslyUseHTMLString: true,
              type: "warning",
          })
              .then(() => {
                  this.actionindex = "D";
                  var delrow = this.$refs.lXTable.getCurrentRow();
                  if (delrow) {
                      var alld = this.$refs.lXTable.tableData;
                      var rowindex = alld.indexOf(delrow);
                      this.save().then((res) => {
                          if (res.errcode == "1") {
                              this.$refs.lXTable.remove(delrow);
                              this.lXTableData.splice(rowindex, 1);
                              let havedata = this.$refs.lXTable.tableData;
                              if (havedata.length > 0) {
                                  if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                                  let selectrow = havedata[rowindex];
                                  this.HightLightRow(selectrow);
                              } else {
                                  this.HightLightRow(false);
                              }
                              this.actionindex = "M";
                          } else {
                              this.$alert(res.errmsg, "出错");
                          }
                      });
                  }
              })
              .catch((e) => {
                  this.$message({
                      type: "info",
                      message: "已取消删除",
                  });
              });
      },
      //取消 -- 取消操作，数据还原
      BtnClear() {
          this.$confirm("您确定要取消这次改动吗？", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          })
              .then(() => {
                  this.bChangeFlag = false;
                  if (this.$refs.lXTable.tableData.length > 0) {
                      this.detailQuery(this.selrow);
                  } else {
                      this.bNullFlag = true;
                      this.detailData = {};
                      this.rXTableData = [];
                  }
              })
              .catch((e) => {});
      },
      //保存 -- 保存新增，修改，删除主表: inv_vendor 子表: inv_vendor_eval
      async BtnSave() {
          try {
              if (this.actionindex != "D") {
                  if (!this.detailData.vendorcode) {
                      this.$alert("供应商代码不能为空！");
                      this.$refs.input1.focus();
                      return false;
                  }
                  if (!this.detailData.vendorname) {
                      this.$alert("供应商名称不能为空！");
                      this.$refs.input2.focus();
                      return false;
                  }
              }

              let data = this.$refs.rXTable.getTableData().fullData;
              for (let i = 0, len = data.length; i < len; i++) {
                  data[i].vendorid = this.detailData.vendorid;
              }

              const res = await this.save();
              if (res.errcode == "1") {
                  this.$message.success("保存成功！");
                  this.bChangeFlag = false;
                  if (this.actionindex == "A") {
                      this.detailData.vendorid = res.thekey;
                      if (this.AddData.indexOf(this.detailData.vendorid) == -1) this.AddData.push(this.detailData.vendorid);

                      this.$refs.lXTable.insert(this.detailData).then(({ row }) => {
                          row.vendorid = res.thekey;
                          this.HightLightRow(row);
                          this.lXTableData.push(row);
                      });
                  } else if (this.actionindex == "M") {
                      if (this.ModData.indexOf(this.detailData.vendorid) == -1) this.ModData.push(this.detailData.vendorid);
                      await this.SetToTable(this.detailData).then((row) => {
                          this.HightLightRow(row);
                      });
                  } else {
                      this.actionindex = "M";
                  }
              } else {
                  this.ErrorCatch(res.errmsg, "保存失败:", "error");
              }
          } catch (e) {
              this.ErrorCatch(e, "", "error");
          }
      },
      save() {
          return this.$tool.request({
              url: "INV/INV1/INV123",
              method: "post",
              timeout: 600000,
              data: {
                  action: "inv_vendor_save",
                  utype: this.actionindex,
                  oldinfo: this.tmpdetailData,
                  newinfo: this.detailData,
                  invvendoreval: this.$refs.rXTable.getRecordset(),
              },
          });
      },
      BtnSync() {
          this.bLoading = true;
          this.$tool
              .request({
                  url: "INV/INV1/INV123",
                  method: "post",
                  timeout: 600000,
                  data: {
                      action: "syncdata",
                  },
              })
              .then((response) => {
                  if (response.err == 0) {
                      let msg = response.msg;
                      if (!msg) msg = "同步数据获取失败！";
                      this.bLoading = false;
                      this.$alert(msg);
                      return false;
                  } else {
                  }
                  this.BtnQuery();
                  this.$message({
                      type: "warining",
                      message: "供应商字典数据更新完成！",
                  });
                  this.bLoading = false;
              })
              .catch((e) => {
                  this.$alert(e, "error");
                  this.bLoading = false;
              });
      },
      //导出
      BtnExport() {
          // this.$refs.lXTable.exportCsv({
          //     filename: "INV123 供应商维护",
          // });console.log("111");

          let tableColumn = this.$refs.lXTable.getColumns();
          let extableColumn = [];
          tableColumn.forEach((item) => {
              extableColumn.push({ title: item.title, field: item.property });
          });
          this.$pub.exportTableExcel(this.showLXTableData, extableColumn, "INV123 供应商维护.xlsx");
      },
      BtnClose() {
          let index = this.$parent.$refs.itemtags.tagsList.findIndex((m) => m.name == "INV123");
          this.$parent.$refs.itemtags.tagsList.splice(index, 1);
          this.$router.go(-1);
      },
      //提示
      ErrorCatch(e, msg, type) {
          this.$alert(msg + e, "提示", {
              confirmButtonText: "确定",
              type: type ? type : "error",
          });
      },
      //--------------- 数据改变及其他功能 ---------------//
      //行改变事件
      async CurrentChangeEvent({ row }) {
          if (this.bChangeFlag) {
              this.$refs.lXTable.setCurrentRow(this.selrow);
              return false;
          } else {
              await this.detailQuery(row);
          }
      },
      //保存后不刷新左侧主表,前台赋值。左表赋值
      SetToTable(obj) {
          return new Promise((s, f) => {
              this.selrow.vendorid = obj.vendorid;
              this.selrow.invorgid = obj.invorgid;
              // this.selrow.invorgna = obj.invorgna;
              this.selrow.vendorcode = obj.vendorcode;
              this.selrow.vendorname = obj.vendorname;
              this.selrow.vendorclass = obj.vendorclass;
              this.selrow.address = obj.address;
              this.selrow.contactman = obj.contactman;
              this.selrow.phonecode = obj.phonecode;
              this.selrow.homepage = obj.homepage;
              this.selrow.email = obj.email;
              this.selrow.description = obj.description;
              this.selrow.inputcode = obj.inputcode;
              this.selrow.vendorna = obj.vendorna;
              this.selrow.labdeptid = obj.labdeptid;
              this.selrow.stopflag = obj.stopflag;
              s(this.selrow);
              return;
          });
      },
      // 焦点跳转
      NextFocus(index) {
          var focusIndex = index + 1;
          var that = this;
          if (index < 13) {
              setTimeout(function () {
                  if (index == 1 || index == 6 || index == 7) {
                      that.$refs["input" + index].blur();
                  }
                  if (index != 4) {
                      that.$refs["input" + focusIndex].focus();
                  } else {
                      that.$refs["input" + focusIndex].$el.focus();
                  }
              }, 5);
          } else {
              return false;
          }
      },
      ActiveMethod({ row }) {
          return true;
      },
      //数据发生改变 -- 按钮禁用/可用切换
      HasChange() {
          this.bChangeFlag = true;
      },
      //获取输入码
      getInputCode() {
          this.detailData.inputcode = this.$pub.CreateInputcode(this.detailData.vendorname, this, 16);
          this.detailData.vendorna = this.detailData.vendorname.substring(0, 16);
      },
      //设置高亮选中行
      async HightLightRow(row) {
          if (!!row) {
              this.$refs.lXTable.setCurrentRow(row);
              this.bNullFlag = false;
              await this.detailQuery(row);
          } else {
              this.$refs.lXTable.setCurrentRow(null);
              this.bNullFlag = true;
              this.detailData = {};
              this.tmpdetailData = {};
              this.rXTableData = [];
          }
      },
      //点击全选
      Focus(event) {
          event.currentTarget.select();
      },
      //----------------- class -----------------//
      //左侧主表 class
      lRowClassName({ row, rowIndex }) {
          if (row.stopflag == "1" || row.stopflag == 1) {
              return "rm-alert";
          }
          if (this.AddData.indexOf(row.vendorid) > -1) {
              return "row-new";
          }
          if (this.ModData.indexOf(row.vendorid) > -1) {
              return "row-modify";
          }
      },
      //右侧子表 class
      rRowClassName({ row, rowIndex }) {
          if (this.$refs.rXTable.hasRowInsert(row)) {
              return "row-new";
          }
          if (this.$refs.rXTable.hasRowChange(row)) {
              return "row-modify";
          }
      },
      rCellClassName({ column, row }) {
          if (column.property == "vendevid" || column.property == "createuserna" || column.property == "createdate") {
              return "col-readonly";
          }
      },
  },
};
</script>

<style scoped>
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}

.pagetop {
  width: 100%;
  height: 65px;
  display: -webkit-box;
  -webkit-box-pack: left;
  /* -webkit-box-align: center;*/
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 70px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.detail-operation {
  display: flex;
  padding: 0px 2px 0px 5px;
  margin: 5px 0;
}
/deep/.el-textarea__inner {
  display: block;
  resize: vertical;
  padding: 2px 4px;
}
/deep/ .el-button.is-disabled {
  border: 0px;
  color: grey;
  background-color: #e6e6e6;
  font-weight: normal;
}
/deep/ tr.vxe-body--row.row-modify {
  color: blue;
}
/deep/ tr.vxe-body--row.row-new {
  color: #cc6600;
}
/deep/ .col-readonly {
  background-color: #eeeeee;
}
/deep/.el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}
/deep/.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #000000;
}
/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}
/deep/ .el-input.is-disabled .el-input__inner {
  color: #000000;
}
/deep/ tr.vxe-body--row.row--current {
  color: #000000;
  font-weight: bold;
}
/deep/.vxe-table .vxe-cell {
  padding: 0 5px 0 5px;
}
</style>
